package cn.opopopo.design_pattern_learn.行为型.memento;

// 4. 测试类
public class MementoPatternDemo {
    public static void main(String[] args) {
        TextEditor editor = new TextEditor();
        History history = new History();

        // 输入文本并保存状态
        editor.setContent("第一版：Hello");
        history.push(editor.save());

        editor.setContent("第二版：Hello World");
        history.push(editor.save());

        editor.setContent("第三版：Hello World!");
        System.out.println("当前内容: " + editor);

        // 撤销一次
        TextMemento lastState = history.pop();
        if (lastState != null) {
            editor.restore(lastState);
        }
        System.out.println("撤销一次后: " + editor);

        // 再撤销一次
        lastState = history.pop();
        if (lastState != null) {
            editor.restore(lastState);
        }
        System.out.println("再撤销一次后: " + editor);
    }
}